import React, { Component } from 'react';
import { StoreProvider, msg } from 'iflux2';
import AppStore from './store';

import { Form } from 'antd';
import Search from './component/search-form';
import List from './container/list';
import { Order_Waite_Audit_Filter, Order_Audited_Filter, Order_Wait_Refund_Filter} from './constant/columns.js';

@StoreProvider(AppStore)
export default class OrderList extends Component {

    constructor(props){
        super(props);
    }

    componentDidMount() {
        //this.props.store.setOrderStatus((this.props.params.type || 'ALL').toUpperCase());
        this.changeFilters(this.props.params.type);
        this.props.store.queryOrderList();//查询订单列表
        
    
    }

    componentWillReceiveProps(nextProps) {
        /**
         * 路由分为：
         * auditing：退货申请单 订单和客服角色
         * audited：退货单  订单和客服角色
         * waitrefund:待退款   会计角色
         * 
         * 当路由切换时，过滤条件也会变
         */
        if (this.props.params.type != nextProps.params.type) {
            this.changeFilters(nextProps.params.type);

            //重置搜索关键字
            this.props.store.setSearchParam({});
            //this.props.store.setOrderStatus(nextProps.params.type === "auditing" ? this.waitFilters || this.auditedFilters);
            //页面变化：触发form.resetFields(),scrollToTop()
            msg.emit("page_changed");
            this.props.store.resetPagination();
            this.props.store.queryOrderList();
        }
    }

    changeFilters = (type) =>{
        const store = this.props.store;
         if(type === 'auditing'){
             //退货申请，设置相应过滤条件和默认过滤条件
            store.setFilters(Order_Waite_Audit_Filter);
            store.setOrderStatus(Order_Waite_Audit_Filter[0].key);
        }else if(type === 'audited'){
            //退货单，设置相应过滤条件和默认过滤条件
            store.setFilters(Order_Audited_Filter);
            store.setOrderStatus(Order_Audited_Filter[0].key);
        }else{
            //waitrefund,待退款
            store.setFilters(Order_Wait_Refund_Filter);
            store.setOrderStatus(Order_Wait_Refund_Filter[0].key)
        }
    }

    render() {
        return (
            <div className="order-list">
                <Search />
                <List type={this.props.params.type}/>
            </div>
        )
    }
}